package com.dq.mail.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dq.mail.entity.Spot;
import com.dq.mail.entity.vo.PageResult;
import com.dq.mail.service.SpotService;
import com.dq.mail.mapper.SpotMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dq.mail.vo.spot.SpotVo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * (Spot)表服务实现类
 *
 * @author Dq
 * @since 2023-03-07 12:56:26
 */
@Service
public class SpotServiceImpl extends ServiceImpl<SpotMapper, Spot> implements SpotService {
    @Autowired
    private SpotMapper spotMapper;

    @Override
    public PageResult<Spot> querySpots(Page<Spot> page, Spot spot) {
        LambdaQueryWrapper<Spot> queryWrapper = new LambdaQueryWrapper<>();
        if (!StringUtils.isBlank(spot.getTitle())) {
            queryWrapper.likeRight(Spot::getTitle, spot.getTitle());
        }
        Page<Spot> spotPage = spotMapper.selectPage(page, queryWrapper);
        PageResult<Spot> spotResult = new PageResult<Spot>(spotPage.getRecords(), spotPage.getTotal(), spotPage.getCurrent(), spotPage.getSize());
        return spotResult;
    }

}